package kbpost

import (
	"context"
	// "fmt"
	"strconv"
	"time"

	"mall/common/globalkey"
	"mall/common/utils/pointy"
	"mall/service/backend/api/internal/svc"
	"mall/service/backend/api/internal/types"
	"mall/service/backend/common/i18n"

	// "github.com/sirupsen/logrus"
	"github.com/zeromicro/go-zero/core/logx"
)

type GetPredefinedListLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewGetPredefinedListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetPredefinedListLogic {
	return &GetPredefinedListLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *GetPredefinedListLogic) GetPredefinedList() (*types.CMSPostPredefinedListResp, error) {
	formDefault := []*types.MetaInfo{
		{
			Key:   pointy.GetPointer("status"),
			Value: pointy.GetPointer(strconv.Itoa(int(globalkey.PostStatusPending))),
		},
		{
			Key:   pointy.GetPointer("visibility"),
			Value: pointy.GetPointer(strconv.Itoa(int(globalkey.PostVisibilityPublic))),
		},
		{
			Key:   pointy.GetPointer("publicTime"),
			Value: pointy.GetPointer("1"),
		},
		{
			Key:   pointy.GetPointer("permalinkTemplate"),
			Value: pointy.GetPointer(l.svcCtx.Config.NfsConf.SiteUrl + time.Now().Format("/2006/01/02/")),
		},
	}

	statusList := []*types.MetaInfo{
		{
			Key:   pointy.GetPointer("publish"),
			Name:  pointy.GetPointer("已发布"),
			Slug:  pointy.GetPointer("publish"),
			Value: pointy.GetPointer(strconv.Itoa(int(globalkey.PostStatusPublish))),
		},
		{
			Key:   pointy.GetPointer("draft"),
			Name:  pointy.GetPointer("草稿"),
			Slug:  pointy.GetPointer("draft"),
			Value: pointy.GetPointer(strconv.Itoa(int(globalkey.PostStatusDraft))),
		},
		{
			Key:   pointy.GetPointer("future"),
			Name:  pointy.GetPointer("定时发布"),
			Slug:  pointy.GetPointer("future"),
			Value: pointy.GetPointer(strconv.Itoa(int(globalkey.PostStatusFuture))),
		},
		{
			Key:   pointy.GetPointer("private"),
			Name:  pointy.GetPointer("对外隐藏"),
			Slug:  pointy.GetPointer("private"),
			Value: pointy.GetPointer(strconv.Itoa(int(globalkey.PostStatusPrivate))),
		},
		{
			Key:   pointy.GetPointer("pending"),
			Name:  pointy.GetPointer("待审核"),
			Slug:  pointy.GetPointer("pending"),
			Value: pointy.GetPointer(strconv.Itoa(int(globalkey.PostStatusPending))),
		},
		{
			Key:   pointy.GetPointer("rejected"),
			Name:  pointy.GetPointer("审核驳回"),
			Slug:  pointy.GetPointer("rejected"),
			Value: pointy.GetPointer(strconv.Itoa(int(globalkey.PostStatusRejected))),
		},
		{
			Key:   pointy.GetPointer("trash"),
			Name:  pointy.GetPointer("回收站"),
			Slug:  pointy.GetPointer("trash"),
			Value: pointy.GetPointer(strconv.Itoa(int(globalkey.PostStatusTrash))),
		},
	}

	metaKeyList := []*types.MetaInfo{
		{
			Key:  pointy.GetPointer("title"),
			Name: pointy.GetPointer("标题"),
			Slug: pointy.GetPointer("title"),
		},
		{
			Key:  pointy.GetPointer("keywords"),
			Name: pointy.GetPointer("关键词"),
			Slug: pointy.GetPointer("keywords"),
		},
		{
			Key:  pointy.GetPointer("description"),
			Name: pointy.GetPointer("描述"),
			Slug: pointy.GetPointer("description"),
		},
	}

	visibilityList := []*types.MetaInfo{
		{
			Key:   pointy.GetPointer("public"),
			Name:  pointy.GetPointer("公开"),
			Slug:  pointy.GetPointer("public"),
			Value: pointy.GetPointer(strconv.Itoa(int(globalkey.PostVisibilityPublic))),
		},
		{
			Key:   pointy.GetPointer("password"),
			Name:  pointy.GetPointer("密码保护"),
			Slug:  pointy.GetPointer("password"),
			Value: pointy.GetPointer(strconv.Itoa(int(globalkey.PostVisibilityPasswordProtected))),
		},
		{
			Key:   pointy.GetPointer("private"),
			Name:  pointy.GetPointer("私密"),
			Slug:  pointy.GetPointer("private"),
			Value: pointy.GetPointer(strconv.Itoa(int(globalkey.PostVisibilityPrivate))),
		},
	}

	stickyList := []*types.MetaInfo{
		{
			Key:   pointy.GetPointer("category"),
			Name:  pointy.GetPointer("香识页显示"),
			Slug:  pointy.GetPointer("category"),
			Value: pointy.GetPointer(strconv.Itoa(int(globalkey.BlogStickyTypeCategory))),
		},
	}

	relationList := []*types.MetaInfo{
		{
			Key:   pointy.GetPointer("perfumes"),
			Name:  pointy.GetPointer("香水"),
			Slug:  pointy.GetPointer("perfumes"),
			Value: pointy.GetPointer("brands,perfumers,fragrance families,top notes,heart notes,base notes,year,gender"),
		},
		{
			Key:   pointy.GetPointer("versions"),
			Name:  pointy.GetPointer("历史版本"),
			Slug:  pointy.GetPointer("versions"),
			Value: pointy.GetPointer("year"),
		},
	}

	return &types.CMSPostPredefinedListResp{
		BaseDataInfo: types.BaseDataInfo{
			Success: true,
			Msg:     l.svcCtx.Trans.Trans(l.ctx, i18n.Success),
		},
		Data: types.CMSPostPredefinedListInfo{
			FormDefault:    formDefault,
			StatusList:     statusList,
			MetaKeyList:    metaKeyList,
			VisibilityList: visibilityList,
			StickyList:     stickyList,
			RelationList:   relationList,
		},
	}, nil
}
